layui.use(['form', 'button', 'popup', 'upload'], function() {
    let $ = layui.jquery;
    var form = layui.form;
    var button = layui.button;
    var popup = layui.popup;
    form.on('submit(Check)', function(obj) {
    showLoadingMessage('正在更新中,请稍后...');
      
      $.ajax({
          url: "/h/ajax/up",
          dataType: 'json',
          type: 'post',
          success: function(res) {
              hideLoadingMessage();
            if (res.code == 1) {
              layer.msg(res.msg, {
                icon: 1,
                time: 1000
              }, function() {
                window.location.reload();
              });
            } else {
              layer.msg(res.msg, {
                icon: 2,
                time: 1000
              });
            }
          },
          error:function(){
              hideLoadingMessage()
              layer.msg("服务器错误！", {
                icon: 2,
                time: 1000
              });
          }
    })

      return false;
    });

    function showLoadingMessage(message) {
      var index = layer.msg(message, {
        icon: 16,
        time: 3000
      });
      return index;
    }

    function hideLoadingMessage() {
      layer.closeAll('loading');
    }

    function showErrorMessage(message) {
      layer.msg(message, {
        icon: 5,
        time: 3000
      });
    }
})
